import 'dart:convert'; // 导入 utf8 编码器
import 'dart:typed_data'; // 导入 Uint8List
class Dart1{
  void test(){
    String str = "FE0F00000040E306EC0301CC29010201280003012800AAAA22000000000000000000000000000000000000000000000000000000000000000000000000010000000000002A00";
    // 将字符串转换为字节数组
    Uint8List bytes = Uint8List.fromList(utf8.encode(str));
    int crc = calculateCRC(bytes);
   String crcL= (crc & 0xFF).toRadixString(16).padLeft(2, '0').toUpperCase();
   String crcH= ((crc >> 8) & 0xFF).toRadixString(16).padLeft(2, '0').toUpperCase();

    // 输出 CRC 校验码的高位和低位字节
    print('CRC: 0x${crcH}${crcL}');
    print('嘿嘿嘿');
  }
  int calculateCRC(List<int> data) {
    int crc = 0xFFFF;

    for (int byte in data) {
      crc ^= byte;
      for (int i = 0; i < 8; i++) {
        if ((crc & 0x0001) != 0) {
          crc >>= 1;
          crc ^= 0xA001;
        } else {
          crc >>= 1;
        }
      }
    }
    return crc;
  }
}